1. Field of the Invention
The present invention relates generally to systems and methods for concurrent processing, and more particularly to systems and methods for multithreaded execution. Still more particularly, the present invention is a system and method for custom context switching within a multithreaded execution environment.
2. Description of the Background Art
In a multithreaded execution environment, a thread is a set of instructions requiring execution. In such an environment, multiple threads generally require execution at any given time. Because processing resources are limited, execution is transferred from one thread to another to ensure that each thread receives some execution time and to give the appearance of continuous execution to a computer user.
A set of data that provides the most-current execution state of a particular thread is referred to as that thread's context. When execution is to be transferred from a first, currently-executing thread to a second thread, the execution of the first thread is stopped. Next, the first thread's context is saved by storing the contents of a predetermined set of registers into a set of memory locations associated with the first thread. Typically, the set of registers consists of one or more processing unit registers, and, if a floating point unit is present, one or more floating point unit registers. This same set of registers is then loaded with the contents of a set of memory locations associated with the second thread, thereby "restoring" the second thread's context. After the second thread's context has been restored, execution of the second thread can proceed. The saving of the first thread's context followed by the restoring of the second thread's context is conventionally referred to as a context switch. In the context switch, the first thread is referred to herein as being "switched-out" after its context has been saved. In an analogous manner, the second thread is referred to herein as being "switched-in" after its context has been restored.
In general, a large number of threads may be present in a multithreaded execution environment. A given thread executes for a limited amount of time, after which a conventional context switch is performed, after which another thread executes for a limited amount of time, after which a conventional context switch is performed, after which yet another thread executes for a limited amount of time, after which a conventional context switch is performed, and so on.
Any given thread may need to routinely perform one or more operations immediately before being switched-out, or immediately after being switched-in. The exact operations required may vary from one thread to another. The conventional context switch consists of an identical set of operations that are performed regardless of the particular threads involved. Thus, in the prior art, when a thread requires operations beyond those provided by the conventional context switch, program instructions for performing such operations must be included in the thread itself. This in turn increases thread complexity and thread memory storage requirements. When the additional operations required by a thread are related to the presence of particular system resources, the portability or reusability of the thread is also negatively affected.
What is needed is a means for selectively performing operations beyond those performed in the conventional context switch.